<?php
error_reporting(0);

session_start();
if(isset($_SESSION['username'])){
    $username = $_SESSION['username'];
    include('./connect.php');
    if ($conn->connect_error) {
        // echo '数据库连接失败！';
        exit(0);
    } else {
        //查询书签
        $sql_book_select = "select * from book where book_user = '$username'";
        $result_book = $conn->query($sql_book_select);
        if (!$result_book) {
            // echo '<script>alert("输入错误");</script>';
            // printf("Error: %s\n", mysqli_error($conn));//打印错误信息
            exit();
        }
        $number_book = mysqli_num_rows($result_book);

        if($number_book){
            
            while($row_book = mysqli_fetch_assoc($result_book)){
                $book = array(
                    'bookid' => $row_book['book_id'],
                    'bookicon' => $row_book['book_icon'],
                    'bookname' => $row_book['book_name'],
                    'bookurl' => $row_book['book_url'],
                    'bookcata' => $row_book['book_cata'],
                );
                $booklist[] = $book;
            }
            echo json_encode($booklist);
        }
    }
}
?>